package com.visec.hdy.hadoop.context;

import java.io.File;
import java.util.List;

import com.visec.hdy.hadoop.standard.Context;

/**
 * 
 * @author hdy
 *
 * @param <K>
 */
public class DefaultContextImpl implements Context {
	protected final long count;
	protected long current;
	protected String folder;

	public DefaultContextImpl(String folder, long count) {
		this.folder = folder;
		this.count = count;
		this.current = 0;
	}

	@Override
	public long count() {
		return count;
	}

	@Override
	public long current() {
		return current;
	}

	@Override
	public long rest() {
		return count - current;
	}

	@Override
	public void skip(long l) {
		current += l;
		if (current > count) {
			current = count;
		}
		if (current < 0) {
			current = 0;
		}
	}

	@Override
	public String getFolder() {
		return folder;
	}

	@Override
	public List<File> sortFiles(List<File> files) {
		return files;
	}

	@Override
	public void back(long l) {
		skip(-l);
	}

	@Override
	public void seek(long l) {
		current = l;
	}

}
